/**
 *    Copyright (C) 2008  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_API_TYPES_HPP
#define	_CUBEFS_API_TYPES_HPP

#include <string>

namespace cubefs    {


struct GlobalConstants {
    //defaults:
    static const int KIND = 0;

    //values:
    static const int CACHE_LINE_WIDTH = 64;
};



typedef long long           BigInt;
typedef long                Long; // internal use only. no api
typedef int                 Int;
typedef short               Short;
typedef char                Byte;
typedef unsigned int        UInt;
typedef unsigned short      UShort;
typedef unsigned char       UByte;

typedef std::string                                                             String;
typedef const std::string&                                                      StringRef;

typedef Byte        PageDescriptor;
typedef Byte        TxnDescriptor;

typedef UInt         ModelIdType;

const int PAGE_TYPE_NEWLY_CREATED       = 0;
const int PAGE_TYPE_SUPERBLOCK          = 1;

const bool VALUE_MAP                    = true;
const bool INDEX_MAP                    = false;

template <Int Value>
struct CodeValue {
    static const Int Code = Value;
};

struct Superblock:  public CodeValue<0> {};
struct Root:        public CodeValue<1> {};
struct KVMap:       public CodeValue<2> {};
struct IdxMap:      public CodeValue<3> {};
struct DFUDS:       public CodeValue<4> {};
struct LOUDS:       public CodeValue<5> {};
struct BlobMap:     public CodeValue<6> {};

struct NullType {
    typedef NullType List;
};

struct EmptyType {};
struct IncompleteType;

template <typename Name>
struct TypeNotFound;
struct TypeIsNotDefined;

template <typename Name>
struct PrintType;

template <typename FirstType, typename SecondType>
struct Pair {
    typedef FirstType   First;
    typedef SecondType  Second;
};

template <typename First, typename Second, typename Fird>
struct Tripple {
    typedef First   first;
    typedef Second  second;
    typedef Fird    fird;
};

template <BigInt Code>
struct TypeCode {
    static const BigInt Value = Code;
};


struct TrueValue {
    static const bool Value = true;
};

struct FalseValue {
    static const bool Value = false;
};


template <typename HeadType, typename TailType = NullType>
struct TypeList {
    typedef TypeList<HeadType, TailType>    List;

    typedef HeadType                        Head;
    typedef TailType                        Tail;
};

template <typename Type_, Type_ V>
struct ValueWrapper {
    typedef Type_               Type;
    static const Type Value     = V;
};

template <typename T = void>
class Remover {
    const T* ptr_;
public:
    Remover(const T* ptr): ptr_(ptr) {}
    virtual ~Remover() {
        delete ptr_;
    }
};



}

#endif	/* _CUBEFS_API_TYPES_HPP */



